# -*- coding: utf-8 -*-
from datetime import datetime



if __name__ == '__main__':
    print "------------------时间转换为字符串----------------------------------"
    d = datetime(2018, 1, 5)
    print d
    print type(d)
    str_d = str(d)
    print str_d
    print type(str_d)
    strftime = d.strftime("%d-%m-%Y")
    print strftime
    print type(strftime)
    print "---------------字符串转换为时间----------------------------------"
    str = "2018-01-05"
    strptime = datetime.strptime(str,"%Y-%m-%d")
    print strptime
    print type(strptime)
    print "------from dateutil.parser import parse  日期格式要求不严格------------"
    from dateutil.parser import parse
    time_parse = parse(str)
    print time_parse
    print type(time_parse)
    print '------------------------------------------------------------------------'
    import pandas as pd

    series = pd.Series(['2018/1/1', '2018/1/2', '2018/1/3', '2018/1/4', '2018/1/5'], name="course_time")
    print series
    to_datetime = pd.to_datetime(series)
    print to_datetime
    print "------------NAT not a time----------------------"
    series2 = pd.Series(['2018/1/1', '2018/1/2', '2018/1/3', '2018/1/4', '2018/1/5']+[None], name="course_time")
    print series2
    pd_to_datetime = pd.to_datetime(series2)
    print pd_to_datetime